#include <stdio.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <net/if.h>

int main(int argc, char *argv[])
{
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(8080);
    addr.sin_addr.s_addr = inet_addr("192.168.47.165");

    int bind_res = bind(sockfd, (struct sockaddr *)&addr, sizeof(addr));

    //=========================

    struct sockaddr_in myAddr;
    socklen_t myAddrLen = sizeof(myAddr);

    getsockname(sockfd, (struct sockaddr *)&myAddr, &myAddrLen);
    printf("client ip: %s\n", inet_ntoa(myAddr.sin_addr));
    printf("client port: %d\n", ntohs(myAddr.sin_port));

    return 0;
}